home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / mxcode / adpcmsrc / testd_s.c < prev    next >
C/C++ Source or Header  |  1993-10-17  |  2KB  |  59 lines

  1. /* testd - Test adpcm decoder */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <dos.h>
  7.  
  8. struct adpcm_state {
  9.     short      valprev_l;        /* Previous output value */
  10.     char       index_l;          /* Index into stepsize table */
  11.     short      valprev_r;        /* Previous output value */
  12.     char       index_r;          /* Index into stepsize table */
  13. };
  14.  
  15. struct adpcm_state state;
  16.  
  17. void adpcm_coder (short [], char [], int, struct adpcm_state *);
  18. void adpcm_decoder (char [], short [], int, struct adpcm_state *);
  19.  
  20. #define NSAMPLES 20000
  21.  
  22. char   abuf[NSAMPLES/2];
  23. short  sbuf[NSAMPLES];
  24.  
  25. main() {
  26.     FILE    *f, *f2;
  27.     char    fname[64],fname2[64];
  28.     int     n;
  29.  
  30.     printf("ADPCM 4:1 stereo decoder v1.0 by Patrick Aalto 1993\r\n");
  31.     if (_argc < 3 )
  32.     {
  33.         printf("Usage: %s infile outfile\r\n", _argv[0]);
  34.         exit(1);
  35.     }
  36.     strcpy(fname,_argv[1]);
  37.     strcpy(fname2,_argv[2]);
  38.  
  39.     if ( NULL == (f2=fopen(fname2,"wb")) )
  40.     {
  41.         printf("Error opening '%s', terminating..\r\n", fname2);
  42.         exit(4);
  43.     }
  44.     if ( NULL == (f=fopen(fname,"rb")) )
  45.     {
  46.         printf("Error opening '%s', terminating..\r\n", fname);
  47.         exit(4);
  48.     }
  49.     printf("Decoding '%s' into '%s', please wait...\r\n", fname, fname2);
  50.     while( n = fread(&abuf,1,sizeof(abuf),f) )
  51.     {
  52.     adpcm_decoder(abuf, sbuf, n, &state);
  53.     fwrite(&sbuf,4,n,f2);
  54.     }
  55.     fclose(f);
  56.     fclose(f2);
  57.     exit(0);
  58. }
  59.